package com.ruubypay.biz.utils.io.file;

import java.io.*;

public class FileTest {
    public static void main(String[] args) {
        updateFile("/Users/haoshuai/Downloads/t");
    }

    public static void updateFile(String dirPath){

        File file = new File(dirPath);
        String[] f = file.list();
        for (String s : f) {
            File f1 = new File(dirPath+"/"+s);
            if(f1.isDirectory()){
//                f1 = new File(dirPath+"/"+s+"/dirtxt.txt");
//                String br = txt2String(f1);
//                br.replace("yuyuiu","ttttt");
                System.out.println("chmod 777 "+s+"/start.sh "+s+"/stop.sh");
//                string2Txt(f1,br+"\r\n678908yuyuiu");
            }
        }
    }
    public static String txt2String(File file){
        StringBuilder result = new StringBuilder();
        try{
            BufferedReader br = new BufferedReader(new FileReader(file));//构造一个BufferedReader类来读取文件
            String s = null;
            while((s = br.readLine())!=null){//使用readLine方法，一次读一行
                result.append(System.lineSeparator()+s);
            }
            br.close();
        }catch(Exception e){
            e.printStackTrace();
        }
        return result.toString();
    }
    public static String string2Txt(File file,String str){
        StringBuilder result = new StringBuilder();
        try{
            BufferedWriter out = new BufferedWriter(new FileWriter(file));
            //\r\n即为换行
            out.write(str);
            //把缓存区内容压入文件
            out.flush();
            //最后记得关闭文件
            out.close();
        }catch(Exception e){
            e.printStackTrace();
        }
        return result.toString();
    }
}
